import Vue from 'vue'
import Router from 'vue-router'
// import HelloWorld from '@/components/HelloWorld'
import Login from '../views/Login'
import Home from '../views/Home'
import Head from '../views/layouts/index'
import accountInfo from '../views/layouts/index'


const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}
Vue.use(Router)

const router = new Router({
    routes: [
        // {
        //   path: '/',
        //   name: 'HelloWorld',
        //   component: HelloWorld
        // }
        // {
        //     path: '/',
        //     name: 'Login',
        //     component: Login
        // },
        {
            path: "/",
            redirect: "/Login"
        },
        {
            name: "Login",
            path: "/Login",
            component: Login
        },
        {
            path: '/Head',
            name: 'Head',
            component: () =>
                import ('../views/layouts/index.vue'),
            children: [{
                    path: '/accountInfo',
                    name: 'accountInfo',
                    // redirect: "/accountInfo",
                    component: () =>
                        import ('../views/accountInfo/index.vue')
                }, {
                    path: "/Chart",
                    name: 'Chart',
                    component: () =>
                        import ('../views/Chart/index.vue')
                },
                {
                    path: "/Introduce",
                    name: 'Introduce',
                    component: () =>
                        import ('../views/Introduce/index.vue')
                },
                {
                    path: "/test",
                    name: 'test',
                    component: () =>
                        import ('../views/test/index.vue')
                }
            ],
        },
        {
            path: '/Home',
            name: 'Home',
            component: Home
                // children: [{
                //   name: "Home",
                //   path: "/Home",
                //   component: () => import("@v/Home.vue")
                // }, ],
        },
        {
            path: '/accountInfo',
            name: 'accountInfo',
            component: () =>
                import ('../views/accountInfo/index.vue')
        },
    ],

})
router.beforeEach((to, from, next) => {
    if (to.path === '/Login') {
        next();
    } else {
        let token = sessionStorage.getItem("token")
        if (token === null || token === '') {
            next('/Login');
            console.log(sessionStorage.getItem("token"))
        } else {
            next();
        }
    }
});
export default router